# Scans DNS for cool names, put together with prefixes, affixes, and middles.
# Usage: ruby DNSScan.rb
#
# Edit the domain composing code as you will. This is perhaps best used to
# make up words, eg. writely. Do not pass untrusted data to this program,
# whois has buffer overflows, so this may be insecure.

pre = ['Fox', 'Web', 'Net', 'Thought', 'Read', 'Work', 'Surf', 'Browse']
mid = ['']
suf = ['Stream','Flow','Link','Line','Focus','Scope','Glide','Fly','Flight','Path','Wing','Eye','First','View', 'Sight','Vision','Hunt','Wind']

# A single whois scan
def scan(x)
  found = system("whois " + x.to_s + " 2>1 | grep -E 'No match for|connect:\
          no route to host' - 1>/dev/null 2>/dev/null")
  puts (found ? "Free: " : "Parked: ") + x
end

# constructs domains (Note: It would be great if ruby had
# an outer join, so I could do (pre*mid*suf).each{...} )

domains = []
pre.map{|i| mid.map{|j| suf.map{|k| domains << i+j+k + ".com" }}}

# Makes threads (avoids blocking)

thrNum = 40
thrArr = (0..thrNum).map{ 
       Thread.new{ scan(domains.pop) while domains.any?}
} 

while (thrArr.any?{|ta| ta.status})
  Thread.pass
end
